package com.example.myapplication.Data;

import com.example.myapplication.Network.NetType;

import org.json.JSONException;
import org.json.JSONObject;

public class Scan extends DataBase{
    public String hostName;
    public String ip;
    public String terminalType;
    public String protocolType;

    public Scan(String hostName,String ip,String protocolType){
        this.hostName = hostName;
        this.ip = ip;
        this.protocolType = protocolType;
        this.terminalType = "Android";
    }

    public Scan(){

    }

//decode encode

    @Override
    public String encodeToJson() throws JSONException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("hostName",hostName);
        jsonObject.put("ip",ip);
        jsonObject.put("protocolType",protocolType);
        jsonObject.put("terminalType",terminalType);
        return String.valueOf(jsonObject);
    }

    public static  Scan decodeFromJson(JSONObject jsonObject) throws JSONException {
        Scan scan = new Scan();
        scan.hostName = jsonObject.getString("hostName");
        scan.ip = jsonObject.getString("ip");
        scan.protocolType = jsonObject.getString("protocolType");
        scan.terminalType = jsonObject.getString("terminalType");
        return scan;
    }

    //接受信息，发送信息
    public void receiveData(){
        //请求回应的报文
        if(this.protocolType.equalsIgnoreCase( NetType.SCAN_MESSAGE_REQ.getDescription() )){

        }else if(this.protocolType.equalsIgnoreCase( NetType.SCAN_MESSAGE_ANS.getDescription() )){

        }
    }

    public void reactReq(Scan remoteScan){
        
    }
}
